<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
if (!defined("Marquee_lib_include")){
    define("Marquee_lib_include", 1);

/**
 * 產生走馬燈檔案
 * /common/Marquee?x_?y.php
 * ?x：表示走馬燈位置
 * ?y：1 -> 繁體版，2 -> 英文版，3 -> 簡體版
 * @return	錯誤時傳回false 程式終止，正確傳回 true
 */
	function MakeMarquee(){
		global $_Conn, $$_Conn, $strTool_lib;
		/*$strSQL = "select * from `bet_MarqueeSite` order by ID";
		if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
			$GLOBALS["errormessage"] = "Make Marquee File Error!!";
			$GLOBALS["errorhidden"] = "\nError: ".PMA_mysql_error($$_Conn)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//若沒有走馬燈位置設定，則傳回 
		if(PMA_mysql_num_rows($RS) == 0)return true;*/
		$arrSite = array(1, 2, 3, 4, 5, 6, 30);

		foreach($arrSite as $intSite){
		//while($Rows = PMA_mysql_fetch_object($RS)){
		//	$intSite = $Rows -> ID;
			$strSQL = "select ID, OnDate, Content_1, Content_2, Content_3, isSystem, isPopup, SpGroup from `bet_Marquee` where isOnline = 1 and OnDate <= CURRENT_DATE() and OffDate >= CURRENT_DATE() and CONCAT(',',Sites,',') like '%,".$intSite.",%' order by ID";

			if(!$subRS = @PMA_mysql_query($strSQL, $$_Conn)){
				$GLOBALS["errormessage"] = "Make Marquee File Error!!";
				$GLOBALS["errorhidden"] = "\nError: ".PMA_mysql_error($$_Conn)."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}

			$strMarquee1 = '$Marquee=array();'."\n";
			$strMarquee2 = '$Marquee=array();'."\n";
			$strMarquee3 = '$Marquee=array();'."\n";
			if(PMA_mysql_num_rows($subRS) > 0){
				while($objNews = PMA_mysql_fetch_object($subRS)){
					preg_match("/@".$intSite."=([^@]+)@/", "@".$objNews -> SpGroup."@", $arrSpGroup);

					$strMarquee1 .= '$Marquee[]=array("ID" => "'.$objNews -> ID.'", "OnDate" => "'.$objNews -> OnDate.'", "isSystem" => "'.$objNews -> isSystem.'", "isPopup" => "'.$objNews -> isPopup.'", "SpGroup" => "'.$arrSpGroup[1].'", "Content" => " '.addslashes($objNews -> Content_1).' ");'."\n";
					$strMarquee2 .= '$Marquee[]=array("ID" => "'.$objNews -> ID.'", "OnDate" => "'.$objNews -> OnDate.'", "isSystem" => "'.$objNews -> isSystem.'", "isPopup" => "'.$objNews -> isPopup.'", "SpGroup" => "'.$arrSpGroup[1].'", "Content" => " '.addslashes($objNews -> Content_2).' ");'."\n";
					$strMarquee3 .= '$Marquee[]=array("ID" => "'.$objNews -> ID.'", "OnDate" => "'.$objNews -> OnDate.'", "isSystem" => "'.$objNews -> isSystem.'", "isPopup" => "'.$objNews -> isPopup.'", "SpGroup" => "'.$arrSpGroup[1].'", "Content" => " '.addslashes($objNews -> Content_3).' ");'."\n";
				}
			}
			@mysql_free_result($subRS);


			$strMarquee1 = "<"."?php \n"."\$MTime = \"".time()."\";\n".$strMarquee1."\n"."?".">";
			$strMarquee2 = "<"."?php \n"."\$MTime = \"".time()."\";\n".$strMarquee2."\n"."?".">";
			$strMarquee3 = "<"."?php \n"."\$MTime = \"".time()."\";\n".$strMarquee3."\n"."?".">";

			if(!writeFile(__Common_Path."/marquee/Marquee".(string)$intSite."_1.php", $strMarquee1, "w+"))return false;
			if(!writeFile(__Common_Path."/marquee/Marquee".(string)$intSite."_2.php", $strMarquee2, "w+"))return false;
			if(!writeFile(__Common_Path."/marquee/Marquee".(string)$intSite."_3.php", $strMarquee3, "w+"))return false;
		}
		return true;
	}  //  MakeMarquee()  //

//-------------------------------------------------------//
// Marquee_lib End
}
?>